package IteratorPattern;

public class BookShelf implements Aggregate {
    private Book[] books;
    private int count;
    private int maxSize;

    public BookShelf(int maxSize) {
        this.books = new Book[maxSize];
        this.maxSize = maxSize;
    }

    public boolean appendBook(Book book) {
        if (this.count >= this.maxSize) {
            return false;
        } else {
            this.books[count] = book;
            this.count++;
            return true;
        }
    }

    public Book getBookAt(int index) {
        return this.books[index];
    }

    public int getCount() {
        return this.count;
    }

    @Override
    public Iterator iterator() {
        return new BookShelfIterator(this);
    }
}
